package com.kun.framework.core.compoment;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.kun.framework.core.exception.ErrorException;
import com.kun.framework.core.exception.WarningException;
import javafx.stage.Stage;

import java.util.Collection;

/**
 * 校验参数的信息弹窗
 *
 * @author gzc
 * @since 2024/9/24
 **/
public class VerifyPopupMessage {

    public static void notBlank(String str, int timed, String message, Stage initOwnerStage) {
        if (StrUtil.isBlank(str)) {
            throwException(true, timed, message, initOwnerStage);
        }
    }

    public static void notEmpty(Collection<?> collection, int timed, String message, Stage initOwnerStage) {
        if (CollUtil.isEmpty(collection)) {
            throwException(true, timed, message, initOwnerStage);
        }
    }

    public static void notNull(Object obj, int timed, String message, Stage initOwnerStage) {
        if (obj == null) {
            throwException(true, timed, message, initOwnerStage);
        }
    }

    public static void notMatch(boolean isMatch, int timed, String message, Stage initOwnerStage) {
        if (!isMatch) {
            throwException(true, timed, message, initOwnerStage);
        }
    }

    public static void notBlankWarning(String str, int timed, String message, Stage initOwnerStage) {
        if (StrUtil.isBlank(str)) {
            throwException(false, timed, message, initOwnerStage);
        }
    }

    public static void notEmptyWarning(Collection<?> collection, int timed, String message, Stage initOwnerStage) {
        if (CollUtil.isEmpty(collection)) {
            throwException(false, timed, message, initOwnerStage);
        }
    }

    public static void notNullWarning(Object obj, int timed, String message, Stage initOwnerStage) {
        if (obj == null) {
            throwException(false, timed, message, initOwnerStage);
        }
    }

    public static void notMatchWarning(boolean isMatch, int timed, String message, Stage initOwnerStage) {
        if (!isMatch) {
            throwException(false, timed, message, initOwnerStage);
        }
    }

    private static void throwException(boolean isErrorType, int timed, String message, Stage initOwnerStage) {
        if (isErrorType) {
            throw new ErrorException(timed, message, initOwnerStage);
        } else {
            throw new WarningException(timed, message, initOwnerStage);
        }
    }

}
